Skip to content

Added filtering for dereferenced nodes#1

Open
AndrzejTSH wants to merge 1 commit intomasterfrom
feature/dereference-filtering
Open

Added filtering for dereferenced nodes#1
AndrzejTSH wants to merge 1 commit intomasterfrom
feature/dereference-filtering

Conversation

@AndrzejTSH
Copy link
Copy Markdown

@AndrzejTSH AndrzejTSH commented Nov 12, 2019

Related https://github.com/Smartum/smartum-core/pull/2537

Ability to filter which schema can be dereferenced by checking its contents.

Usage

    const refParser = require("json-schema-ref-parser");

    refParser.dereference(originalJsonSchemaObj, {
        // dereference the following schemas: model properties, path & query parameters
        dereference: {
            filter: (value) => {
                return ['query', 'path'].includes(value.in)
                    || ['string', 'array', 'integer', 'number', 'boolean'].includes(value.type);
            }
        }
    }).then((schemaDerefed) => {
        // ...
    });

Effect

Before:

      "AccountDepositPaytrailInitRequest": {
        "type": "object",
        "properties": {
          "amount": {
            "$ref": "#/components/schemas/Record/properties/amount"
          },
          "itemName": {
            "$ref": "#/components/schemas/ItemSearchResult/properties/name"
          },
          "userId": {
            "$ref": "#/components/schemas/UserRearchResult/properties/id"
          }
        },
        "required": [
          "amount",
          "itemName"
        ]
      },

After:

      "AccountDepositPaytrailInitRequest": {
        "type": "object",
        "properties": {
          "amount": {
            "type": "integer",
            "description": "Money amount.",
            "example": 17500
          },
          "itemName": {
            "type": "string",
            "description": "Technical name of the product (item).",
            "minLength": 1,
            "maxLength": 128,
            "example": "EXERCISE_EMONEY"
          },
          "userId": {
            "type": "integer",
            "description": "User identifier.",
            "readOnly": true,
            "minimum": 1,
            "example": 1
          }
        },
        "required": [
          "amount",
          "itemName"
        ]
      }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant